package com.sdy.service.Impl;

import com.sdy.dao.mysql.ProductMapper;
import com.sdy.po.Product;
import com.sdy.po.Specification;
import com.sdy.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    ProductMapper productMapper;

    @Override
    public List<Product> getAll() {
        return null;
    }

    @Override
    public Boolean update(Product product) {
        return null;
    }

    @Override
    public Boolean insert(Product product) {
        return null;
    }

    @Override
    public Boolean delete(Product product) {
        return null;
    }


    /**
     * 获得一个不带具体规格的产品
     * @param id
     * @return
     */
    @Override
    public Product getAbstractOne(Integer id) {
        return productMapper.getAbstractOne(id);
    }

    /**
     * 获得一个带具体规格的产品
     * @param id
     * @param specificationId
     * @return
     */
    public Product getConcreteOne(Integer id, Integer specificationId) {
        Product product = productMapper.getAbstractOne(id);
        for (Specification specification:product.getSpecificationList()) {
            if (specification.getId() == specificationId){
                product.setSpecification(specification);
                return product;
            }
        }
        return null;
    }

}
